package LC21;

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}

public class LC2095 {

    public static void main(String[] args) {
        ListNode node = new ListNode(1);
        System.out.println(deleteMiddle(node));
    }

    public static ListNode deleteMiddle(ListNode head) {
        ListNode curr = head;
        int num = 0;
        while (curr != null) {
            num ++;
            curr = curr.next;
        }
        int n = num / 2;
        ListNode pre = new ListNode();
        pre.next = head;
        curr = pre;
        for (int i = 0; i < n; i++) {
            pre = pre.next;
        }
        if (pre.next != null) {
            pre.next = pre.next.next;
        }
        return curr;
    }
}


